package com.ruoyi.project.system.income.controller;

import java.util.List;

import com.ruoyi.project.system.user.domain.User;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.system.income.domain.Income;
import com.ruoyi.project.system.income.service.IIncomeService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;
import org.springframework.web.multipart.MultipartFile;

/**
 * 【请填写功能名称】Controller
 * 
 * @author ruoyi
 * @date 2020-11-25
 */
@Controller
@RequestMapping("/system/income")
public class IncomeController extends BaseController
{
    private String prefix = "system/income";

    @Autowired
    private IIncomeService incomeService;

    @RequiresPermissions("system:income:view")
    @GetMapping()
    public String income()
    {
//        List<RClassification> rClassifications = rClassificationService.selectRClassificationList(null);
//        mmap.put("resumptionType", rClassifications);
        return prefix + "/income";
    }

    /**
     * 查询【请填写功能名称】列表
     */
    @RequiresPermissions("system:income:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(Income income)
    {
        startPage();
        List<Income> list = incomeService.selectIncomeList(income);
        return getDataTable(list);
    }

    /**
     * 导出【请填写功能名称】列表
     */
    @RequiresPermissions("system:income:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(Income income)
    {
        List<Income> list = incomeService.selectIncomeList(income);
        ExcelUtil<Income> util = new ExcelUtil<Income>(Income.class);
        return util.exportExcel(list, "income");
    }

    @Log(title = "导入", businessType = BusinessType.IMPORT)
    @RequiresPermissions("system:income:import")
    @PostMapping("/importData")
    @ResponseBody
    public AjaxResult importData(MultipartFile file, boolean updateSupport) throws Exception
    {
        ExcelUtil<Income> util = new ExcelUtil<Income>(Income.class);
        List<Income> incomeList = util.importExcel(file.getInputStream());
        String message = incomeService.importIncome(incomeList, updateSupport);
        return AjaxResult.success(message);
    }
    @RequiresPermissions("system:income:view")
    @GetMapping("/importTemplate")
    @ResponseBody
    public AjaxResult importTemplate()
    {
        ExcelUtil<Income> util = new ExcelUtil<Income>(Income.class);
        return util.importTemplateExcel("收入数据");
    }
    /**
     * 新增【请填写功能名称】
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存【请填写功能名称】
     */
    @RequiresPermissions("system:income:add")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(Income income)
    {
        return toAjax(incomeService.insertIncome(income));
    }

    /**
     * 修改【请填写功能名称】
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        Income income = incomeService.selectIncomeById(id);
        mmap.put("income", income);
        return prefix + "/edit";
    }

    /**
     * 修改保存【请填写功能名称】
     */
    @RequiresPermissions("system:income:edit")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(Income income)
    {
        return toAjax(incomeService.updateIncome(income));
    }

    /**
     * 删除【请填写功能名称】
     */
    @RequiresPermissions("system:income:remove")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(incomeService.deleteIncomeByIds(ids));
    }

    /**
     * 删除【请填写功能名称】
     */
    @RequiresPermissions("system:income:statistical")
    @PostMapping( "/statistical")
    @ResponseBody
    public AjaxResult statistical(String ids)
    {
        return toAjax(incomeService.statisticalByIds(ids));
    }
}
